<?php
class Model_rate extends CI_Model{
	protected $_table = "tbl_tickets";
	protected $_train  = "tbl_trains";
	public function __construct(){
		parent::__construct();
	}
	public function listtrains(){
		$this->db->order_by("train_order","ASC");
		return $this->db->get($this->_train)->result_array();
	}
	public function getalldata($date,$trainid,$type=1){
		$data= $this->db->query("select * from ".$this->_table." where tickdate='$date' and trainid ='$trainid' and ticktype='$type'");
		if($data->num_rows()>0){
			return $data->result_array();
		}else{
			return array(array("tickid"=>"0","tickdate"=>"","tickdeparts"=> "0","tickarrives"=>"0","tickduration"=>"0","softseat"=>"0","hardberth"=>"0","softberth"=>"0","vipberth"=>"0","ticknum"=>"0","ticktype"=>"0","trainid"=>"0"));
		}
	}
	public function update($data,$id){
		$this->db->query("update ".$this->_table." set tickdate='".$data["tickdate"]."',tickdeparts='".$data["tickdeparts"]."',tickarrives='".$data["tickarrives"]."',tickduration='".$data["tickduration"]."',softseat='".$data["softseat"]."',hardberth='".$data["hardberth"]."',softberth='".$data["softberth"]."',vipberth='".$data["vipberth"]."',ticktype='".$data["ticktype"]."',ticknum='".$data["ticknum"]."' where trainid='".$id."' and tickdate='".$data["tickdate"]."'");
	}
	public function updatefield($id,$data){
		if($id != 0){
			$this->db->where("tickid",$id);
			$this->db->update($this->_table,$data);
		}else{
		}
	}
	public function updateall($date,$type,$trainid,$data){
			$this->db->query("insert into ".$this->_table." (tickdate,tickdeparts,tickarrives,tickduration,softseat,hardberth,softberth,vipberth,ticktype,ticknum,trainid) values('".$data["tickdate"]."','".$data["tickdeparts"]."','".$data["tickarrives"]."','".$data["tickduration"]."','".$data["softseat"]."','".$data["hardberth"]."','".$data["softberth"]."','".$data["vipberth"]."','".$data["ticktype"]."','".$data["ticknum"]."','".$data["trainid"]."')");
		//}
   }
}